home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / TESTSCH1.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-29  |  3KB  |  91 lines

  1. program TestSch1;
  2. {------------------------------------------------------------------------------
  3.                               DBase Key Field Locator
  4.  
  5.        TESTSCH1.PAS Copyright (c)  Richard F. Griffin
  6.  
  7.        14 July 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        This program demonstrates how key strings may be located in dBase
  14.        files.
  15.  
  16.        If the GSDMO_01.DBF file does not exist, the program will display a
  17.        a message that the file was not found and to run GSDMO_01 to make
  18.        the file.
  19.  
  20.        Upon execution, the program sets the size of the cache file to a
  21.        maximum of 64512 bytes.  It will then ask for a LASTNAME field key to
  22.        find.  Enter any portion of the string.
  23.  
  24. -------------------------------------------------------------------------------}
  25.  
  26. uses
  27.    GSXT_Sch,
  28.    GSOB_Var,
  29.    GSOB_DBS,
  30.    GSOBShel,
  31.    SmplStuf,
  32.    CRT,
  33.    DOS;
  34.  
  35. var
  36.    St    : string;
  37.    posn : word;
  38.    fnum : word;
  39.  
  40.    h,m,s,c,h1,m1,s1,c1:word;
  41.    rt : real;
  42.  
  43. begin
  44.    DBFCacheSize := 64512;
  45.    ClrScr;
  46.    if not FileExist('GSDMO_01.DBF') then   {Check for the file}
  47.    begin
  48.       writeln('File GSDMO_01.DBF not found.  Run GSDMO_01 to create.');
  49.       halt;
  50.    end;
  51.                        {The 'Real' example starts here}
  52.  
  53.    Select(1);                     {Use record area 1 (the default)}
  54.    Use('GSDMO_01');               {Assign the dBase III file GSDMO_01}
  55.    REPEAT
  56.       write('LASTNAME to search for:');
  57.       readln(St);
  58.       if St <> '' then
  59.       begin
  60.          gettime(h,m,s,c);                {Test the time it takes}
  61.  
  62.          fnum := FieldNo('LASTNAME');
  63.          posn := SearchDBF(St,fnum,true);
  64.          if posn > 0 then                 {Posn = starting position in string}
  65.          begin
  66.             writeln(RecNo,'  ',
  67.                     FieldGet('LASTNAME'),' ',       {Get field images}
  68.                     FieldGet('FIRSTNAME'),'  ',
  69.                     FieldGet('UNIQUEID'));
  70.             writeln(RecNo,' records were searched');
  71.          end
  72.          else
  73.          begin
  74.             writeln('No Match!  ',RecCount,' records were searched');
  75.          end;
  76.  
  77.       {  Report elapsed time  }
  78.  
  79.          gettime(h1,m1,s1,c1);
  80.          if s1 < s then s1 := s1 + 60;
  81.          s := (s*100)+c;
  82.          s1 := (s1*100)+c1;
  83.          rt := s1-s;
  84.          rt := rt/100;
  85.          writeln('Time required to find key was  ',rt:2:2,' seconds.');
  86.       end;
  87.  
  88.    until st = '';
  89.    CloseDataBases;                {Close the file}
  90. end.
  91.